import React, {useEffect,useState}from "react";
import FormItem from "./components/Form.jsx";
import { useNavigate } from "react-router-dom";
import { post, get } from "../../api/request.js";
import { message } from "antd";
import "../../mock/index.js";
import "./index.less";
import Warning from "../../utils/modal.js";
export default function Index() {
  let navigate = useNavigate();
  // 提交表单的时候收集数据
  const onFinish = async (values) => {
    console.log(values,'][[]][]][')
    // post写法
    // post( "/test/action",{data:values}).then((res) => {
    //   if(res.data?.status===200){
    //     navigate("/main/*")
    //     message.success("登录成功！")
    //   }
    // });
    let data = await get(
      `/test/action?account=${values.account}&password=${values.password}`
    )
    if(data.data?.status===200){
      const { userInfo } = data.data;
      localStorage.setItem('userInfo',JSON.stringify(userInfo))
      navigate("/main/*")
      // message.success(data.data.msg)
      const args={
        title:'登录提示',
        content:'恭喜您登录成功',
        okText:'确认'
      }
      Warning(args)
    }else{
      message.warn(data.data.msg)
    }
    // .then((res) => {
    //   if (res.data?.status === 200) {
    //     console.log(res.data);
    //     const { userInfo } = res.data;
    //     navigate("/main/*")
    //     message.success(res.data.msg)
    //   }else{
    //     message.warn(res.data.msg)
    //   }
    // });
  };
  return (
    <div className="login">
      <section className="login_content">
        {/* <h2>用户登录</h2> */}
        <FormItem onFinish={onFinish} />
      </section>
    </div>
  );
}
